#include <bits/stdc++.h>
// 2024/08/06
// tag: 差分数组
using namespace std;

int n, m;

class Difference
{
public:
    vector<int> diff;
    Difference(void)
    {
        diff = vector<int>(n + 1);
    }

    // 增加区间[i, j]的值
    void increment(int i, int j, int val)
    {
        diff[i] += val;
        if (j + 1 < diff.size())
        {
            diff[j + 1] -= val;
        }
    }
};

signed main()
{
    cin >> n >> m;
    Difference diff;

    // 读取m个区间，并增加区间[i, j]的值
    for (int i = 1; i <= m; i++) {
        int x, y;
        cin >> x >> y;
        diff.increment(x, y, 1);
    }

    int t = 0, cnt = 0;
    // 遍历差分数组，计算区间内值为0的个数
    for (auto x: diff.diff){
        t += x;
        cnt += !t;
    }

    cout << cnt;

    return 0;
}